﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using DAOExceptions;


namespace SQLDao
{
    public class SQL_DAO_Connection
    {
        public static readonly string ConStr = ConfigurationManager.ConnectionStrings["default"].ConnectionString;
        public static SqlConnection Connection
        { get; private set; }
        public static void Connect()
        {
            if (Connection == null)
            {
                if (ConStr == null)
                {
                    throw new DAOException("Couldn't read the connection string");
                }
                Connection = new SqlConnection();
            }
            if (Connection.State != System.Data.ConnectionState.Open)
            {
                try
                {
                    Connection.Open();
                }
                catch (SqlException)
                {
                    throw new DAOException("Couldn't connect to sql server");
                }
            }
        }

        private SQL_DAO_Connection()
        {
        }
    }
}
